package zhieasy.cn.service.initiation.impl;

import org.springframework.stereotype.Service;
import zhieasy.cn.common.utils.KeyUtil;
import zhieasy.cn.model.common.SiteLocation;
import zhieasy.cn.model.initiation.SchoolSiteType;
import zhieasy.cn.persistence.mapper.common.SiteLocationMapper;
import zhieasy.cn.persistence.mapper.initiation.SchoolSiteTypeMapper;
import zhieasy.cn.service.initiation.SiteLocationService;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author sofency
 * @date 2020/8/1 19:12
 * @package IntelliJ IDEA
 * @description
 */
@Service
public class SiteLocationServiceImpl implements SiteLocationService {

    @Resource
    private SiteLocationMapper siteLocationMapper;

    @Resource
    private SchoolSiteTypeMapper schoolSiteTypeMapper;

    /**
     * 插入地点
     * @param siteLocation
     * @return
     */
    @Override
    public boolean insertPlace(SiteLocation siteLocation) {
        siteLocation.setSiteId(KeyUtil.genUniqueKey());//设置唯一的主键
        siteLocation.setCreateTime(System.currentTimeMillis());//设置创建时间
        siteLocation.setUpdateTime(System.currentTimeMillis());//设置修改时间
        siteLocation.setIsDelete(2);//表示含义未知 可以用枚举类来替换
        int insert = siteLocationMapper.insert(siteLocation);
        return insert == 1;
    }

    /**
     * 修改地点
     * @param siteLocation
     * @return
     */
    @Override
    public void updatePlace(SiteLocation siteLocation) {
        siteLocation.setUpdateTime(System.currentTimeMillis());//设置修改时间
        siteLocationMapper.updateById(siteLocation);
    }


    /**
     * 获取所有的地点
     * @return
     */
    @Override
    public List<SiteLocation> getPlace() {
        return siteLocationMapper.selectList(null);
    }

    //根据经纬度获取地点的详情
    @Override
    public SiteLocation getPlaceById(String siteId){
        return siteLocationMapper.selectById(siteId);
    }

    //根据地点类型获取地点的信息
    @Override
    public List<SiteLocation> getPlacesList(String typeId){
        Map<String,Object> map = new HashMap<>();
        map.put("site_type_id",typeId);
        return siteLocationMapper.selectByMap(map);
    }

    /**
     * 获取所有的地点类型
     * @return
     */
    @Override
    public List<SchoolSiteType> getTypeList() {
        return schoolSiteTypeMapper.selectList(null);
    }

}
